#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2009-1-12 上午01:27:58 
#Create By: Fla.sam
#
#DESC: 
#
#-------------------------------------------------


from django.contrib.auth.models import User, Group
from django.db import models
# Create your models here.

class SiteMessage( models.Model ):
    
    message_title = models.CharField( max_length = 100, verbose_name = '标题' )
    message_content = models.TextField( verbose_name = '内容' )
    message_send_datetime = models.DateTimeField( auto_now_add = True )
    
    class Meta:
        abstract = True

    
class PrivateMessage( SiteMessage ):
    
    message_from = models.ForeignKey( User, related_name = 'pm_from_user', verbose_name = '撰写人', help_text = '站内私信的撰写人' )
    message_to_user = models.ForeignKey( User, related_name = 'pm_to_user', verbose_name = '传送用户', help_text = '将站内私信发送给用户' )
    message_is_read = models.BooleanField( verbose_name = '是否已读', help_text = '站内私信是否已被接收者阅读', default = False )
    message_read_datetime = models.DateTimeField( blank = True )

    def __unicode__( self ):
        return u'From:%s To:%s, Title:%s' % ( self.message_from, self.message_from, self.message_title )   
    
    class Meta:
        verbose_name = u'站点私信'
        verbose_name_plural = u'%s管理' % verbose_name
        
class AnnMessage( SiteMessage ):

    message_from = models.ForeignKey( User, related_name = 'message_from_user', verbose_name = '撰写人', help_text = '站内私信的撰写人' )
    message_to = models.ManyToManyField( Group, related_name = 'message_from_group', verbose_name = '广播用户组', help_text = '将站内私信发送给用户组' )
    
    def __unicode__( self ):
        return u'From:%s To:%s, Title:%s' % ( self.message_from, self.message_to, self.message_title )
    
    class Meta:
        verbose_name = u'站点广播消息'
        verbose_name_plural = u'%s管理' % verbose_name
        
    
    